#mysql-connector-python
import mysql.connector                 
import sys
import operator
import time

#获取总数	
def count_resign_safe(connection):
    cursor = connection.cursor()
    try:
        sql_query = 'select count(id) as c from resign_safe where is_delete=0 ;'
        cursor.execute(sql_query);        
        count =  cursor.fetchone(); 
        print (count);
        return count
    except mysql.connector.Error as e:
        print('query error!{}'.format(e))
    finally:
        cursor.close()
		
#获取总数		
def count_resign_safe_channel(connection,channel):
    cursor = connection.cursor()
    try:
        sql_query = "select count(id) as c from resign_safe where is_delete=0 and channel='%s' ;" % channel
        cursor.execute(sql_query);        
        count =  cursor.fetchone(); 
        print (count);
        return count;
    except mysql.connector.Error as e:
        print('query error!{}'.format(e))
    finally:
        cursor.close()
		
#查询列表	
def query_resign_safe(connection,page,size,channel):
    cursor = connection.cursor()
    try:
        sql_query = "select number,channel from resign_safe where is_delete=0 and channel='%s'  order by id asc limit %d,%d;"%(channel,page-1,size)
        cursor.execute(sql_query)
        for number,channel in cursor:
            print (number,channel)
    except mysql.connector.Error as e:
        print('query error!{}'.format(e))
    finally:
        cursor.close()
		
# 
config = {
    'host': '10.198.197.127',
    'user': 'test',
    'password': 'test',
    'port': 3306,
    'database': 'test',
    'charset': 'utf8'
}
try:
    connection = mysql.connector.connect(**config)    
    count_resign_safe(connection);
    #query_resign_safe(connection,page,size,channel)
    print('\n');
except mysql.connector.Error as e:
    print('connect fails!{}'.format(e))
finally:
    connection.close()